package com.cas.scalls.util;

public class APIException extends Exception {
	private static final long serialVersionUID = 1L;
	public static final int SYSTEM_ERROR	= -1;
	public static final int SERVICE_ERROR	= 1;
	protected int code = SYSTEM_ERROR;
	protected String trace;

	public APIException() {
		super();
		init();
	}

	public APIException(String message) {
		super(message);
		init();
	}
	public APIException(int code, String message) {
		super(message);
		this.code = code;
		init();
	}
	
	public int getCode() {
		return this.code;
	}
	
	public String getMessage() {
		return super.getMessage();	
	}
	
	public String getTrace() {
		return trace;
	}

	private void init() {
		StackTraceElement traces[] = getStackTrace();
		String className = traces[0].getClassName();
		int n = className.lastIndexOf('.');
		if(n > 0) className = className.substring(n + 1);
		//trace = className + "." + traces[0].getMethodName() + "[line: " + traces[0].getLineNumber() + "]: ";
		trace = "0|";
	}
}
